#import "DisplayObjectContainer.h"

@implementation DisplayObjectContainer
@synthesize view;

- (id)init{
	if((self = [super init])){
		view = [[UIView alloc]init];
		layer = view.layer;
	}
	return self;
}

-(DisplayObject*) addChild:(DisplayObject*)aChild{
	if([aChild isKindOfClass:[DisplayObjectContainer class]]){
		DisplayObjectContainer *c = (id)aChild;
		[view addSubview:c.view];
	}else{
		[layer addSublayer:aChild.layer];
	}
	[self dispatchEvent:[[[Event alloc] initWithType: EVENT_ADDED]autorelease]];
	return aChild;
};

-(DisplayObject*) addChildAt:(DisplayObject*)aChild index:(int)aIndex{
	[self dispatchEvent:[[[Event alloc] initWithType: EVENT_ADDED]autorelease]];
	[layer insertSublayer:aChild.layer atIndex:aIndex];
	return aChild;
};

-(BOOL)areInaccessibleObjectsUnderPoint:(CGPoint)aPoint{
	return NO;
};

-(BOOL)contains:(DisplayObject*)aChild{
	return [layer.sublayers containsObject:aChild];
};

-(DisplayObject*)getChildAt:(int)aIndex{
	return [layer.sublayers objectAtIndex:aIndex];
}

-(DisplayObject*)getChildByName:(NSString*)aName{
	return nil;
}

-(int)getChildIndex:(DisplayObject*)aChild{
	return [layer.sublayers indexOfObject:aChild];
};

-(Array*)getObjectsUnderPoint:(CGPoint)aPoint{
	return nil;
};

-(DisplayObject*)removeChild:(DisplayObject*)aChild{
	[aChild.layer removeFromSuperlayer];
	return aChild;
};

-(DisplayObject*)removeChildAt:(int)aIndex{
	[[layer.sublayers objectAtIndex:aIndex] removeFromSuperlayer];
	return nil;
};

-(void)setChildIndex:(DisplayObject*)aChild index:(int)aIndex{

};

-(void)swapChildren:(DisplayObject*)aChild1 child2:(DisplayObject*)aChild2{
};

-(void)swapChildrenAt:(int)aIndex1 index2:(int)aIndex2{
};

-(void)dealloc{
	[view release];
	[super dealloc];
}
@end